package com.example.demo;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.LinkedList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author: Administrator
 * @Date: 2020/12/24 17:03
 */
public class App {


    private static WrapApp app;
    public static void main(String[] args) throws InterruptedException {
//        final AtomicReference<WrapApp> app = new AtomicReference<>();
//        LinkedList<WrapApp> appList = new LinkedList<>();

        ThreadUtil.execute(() -> {
            while(true){
                ThreadUtil.sleep(1000);
                ThreadUtil.execute(() -> {
                    try{
                        System.out.println(HttpUtil.get("http://localhost:8080/test"));
                    } catch (Exception e){
                    }
                });
            }
        });

        //restart thread
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (args != null) {
                    app.refresh();
                }
            }
        }).start();

        app = new WrapApp(args);
        app.start();
        app.join();
    }
}
